package cyou.breathe.dynamictp.spring.base.configuration;

import cyou.breathe.dynamictp.core.alarm.ThreadPoolAlarmChecker;
import cyou.breathe.dynamictp.core.config.BootstrapConfigProperties;
import cyou.breathe.dynamictp.core.monitor.ThreadPoolMonitor;
import cyou.breathe.dynamictp.core.notification.service.NotifierDispatcher;
import cyou.breathe.dynamictp.spring.base.support.ApplicationContextHolder;
import cyou.breathe.dynamictp.spring.base.support.BreatheThreadBeanPostProcessor;
import cyou.breathe.dynamictp.spring.base.support.SpringPropertiesLoader;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;

/**
 * 动态线程池基础 Spring 配置类
 * @author: breathe
 * @createTime: 2025-09-14
 */
@Configurable
public class BreatheThreadBaseConfiguration {

    @Bean
    public ApplicationContextHolder applicationContextHolder() {
        return new ApplicationContextHolder();
    }

    @Bean
    @DependsOn("applicationContextHolder")
    public BreatheThreadBeanPostProcessor breatheThreadBeanPostProcessor(BootstrapConfigProperties properties) {
        return new BreatheThreadBeanPostProcessor(properties);
    }

    @Bean
    public NotifierDispatcher notifierDispatcher() {
        return new NotifierDispatcher();
    }

    @Bean
    public SpringPropertiesLoader springPropertiesLoader() {
        return new SpringPropertiesLoader();
    }

    @Bean(initMethod = "start", destroyMethod = "stop")
    public ThreadPoolAlarmChecker threadPoolAlarmChecker(NotifierDispatcher notifierDispatcher) {
        return new ThreadPoolAlarmChecker(notifierDispatcher);
    }

    @Bean(initMethod = "start", destroyMethod = "stop")
    public ThreadPoolMonitor threadPoolMonitor() {
        return new ThreadPoolMonitor();
    }
}
